from core.basehandler import BaseHandler
from core.room import Room
from core.support import set_cutscene, get_game
from core.action import Action

class TeamRoom230A(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)
        
        # self.treasure_locked = True
        # self.add_item(Keys())
        #self.add_action(TurnOnFlashlight)
        self.add_action(BackToHallway2)
        self.add_action(ReadTheWall)
    
    def flashlight_on(self):
        game = get_game()
        player = game.get_player()
        if 'Flashlight' in player.inventory:
            if player.inventory['Flashlight'].is_lit:
                return True
        return False
    
    def get_description(self):
        if self.flashlight_on():
            game = get_game()
            player = game.get_player()
            if player.has_status("knows_escape_plan"):
                desc = '''
                The room smells of IP sweat and Funyuns, but the crudely drawn image on the chalkboard appears to be an escape plan!
                '''
                
            else:
                desc = '''
                There's something written on the wall! I'd better read it...
                '''
        else:
            desc = "This room looks like a prison cell, just like it always has! It's awfully dark in here... I wish I had some light..."
        return desc
    
    def get_image(self):
        if self.flashlight_on():
            game = get_game()
            player = game.get_player()
            if player.has_status("knows_escape_plan"):
                return 'TeamRoom230A_2.jpg'
            else:
                return 'TeamRoom230A.jpg'
        else:        
            return 'TeamRoom230A_withoutflashlight.jpg'

class TeamRoom230AHandler(BaseHandler):
    def get_room_class(self):
        return TeamRoom230A

class BackToHallway2(Action):
    def __init__(self):
        Action.__init__(self, "BackToHallway2")
    
    def get_description(self):
        return "Step to the hallway"
    
    def get_destination(self):
        return 'secondfloorhallway'
    
    def get_method(self):
        return "get"

class ReadTheWall(Action):
    def __init__(self):
        Action.__init__(self, "ReadTheWall")
    
    def get_description(self):
        return "Read the message on the wall"
    
    def do_action(self,game,room,request):
        player = game.get_player()
        player.add_status("knows_escape_plan")
        set_cutscene("Hot diggity dagnabit!  What a plan!!  Looks like I need to swing down from the second floor and smash the globe over to escape. But what can I swing on? How will I muster up the courage? I should get a drink to ponder...")
        
    def get_method(self):
        return "post"
    
    def is_enabled(self):
        game = get_game()
        player = game.get_player()
        return self.room.flashlight_on() and not player.has_status("knows_escape_plan")